package com.qingke.oms.pojo;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@Table(name="`order`")
public class Order {
	@Id
	@Column(name="id")
	private int id;
	
	@ManyToOne
	@JoinColumn(name="customer_id")
	private User customer;
	
	@ManyToOne
	@JoinColumn(name="shop_id")
	private Shop shop;
	
	@Column(name="total")
	private double total;
	
	@Column(name="create_time",insertable=false)
	private Date createTime;
	
	@Column(name="be_deleted")
	private boolean beDeleted;
	
	@OneToMany(mappedBy="order",fetch=FetchType.LAZY)
	private Set<OrderItem> orderItems;
	
	@OneToMany(mappedBy="order",fetch=FetchType.LAZY)
	private Set<TransactionStatusRecord> transactionStatusRecords;
	
	

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public User getCustomer() {
		return customer;
	}

	public void setCustomer(User customer) {
		this.customer = customer;
	}

	public Shop getShop() {
		return shop;
	}

	public void setShop(Shop shop) {
		this.shop = shop;
	}

	public Set<OrderItem> getOrderItems() {
		return orderItems;
	}

	public void setOrderItems(Set<OrderItem> orderItems) {
		this.orderItems = orderItems;
	}

	public double getTotal() {
		return total;
	}

	public void setTotal(double total) {
		this.total = total;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public boolean isBeDeleted() {
		return beDeleted;
	}

	public void setBeDeleted(boolean beDeleted) {
		this.beDeleted = beDeleted;
	}

	public Set<TransactionStatusRecord> getTransactionStatusRecords() {
		return transactionStatusRecords;
	}

	public void setTransactionStatusRecords(Set<TransactionStatusRecord> transactionStatusRecords) {
		this.transactionStatusRecords = transactionStatusRecords;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (beDeleted ? 1231 : 1237);
		result = prime * result + ((createTime == null) ? 0 : createTime.hashCode());
		result = prime * result + ((customer == null) ? 0 : customer.hashCode());
		result = prime * result + id;
		result = prime * result + ((orderItems == null) ? 0 : orderItems.hashCode());
		result = prime * result + ((shop == null) ? 0 : shop.hashCode());
		long temp;
		temp = Double.doubleToLongBits(total);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result + ((transactionStatusRecords == null) ? 0 : transactionStatusRecords.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Order other = (Order) obj;
		if (beDeleted != other.beDeleted)
			return false;
		if (createTime == null) {
			if (other.createTime != null)
				return false;
		} else if (!createTime.equals(other.createTime))
			return false;
		if (customer == null) {
			if (other.customer != null)
				return false;
		} else if (!customer.equals(other.customer))
			return false;
		if (id != other.id)
			return false;
		if (orderItems == null) {
			if (other.orderItems != null)
				return false;
		} else if (!orderItems.equals(other.orderItems))
			return false;
		if (shop == null) {
			if (other.shop != null)
				return false;
		} else if (!shop.equals(other.shop))
			return false;
		if (Double.doubleToLongBits(total) != Double.doubleToLongBits(other.total))
			return false;
		if (transactionStatusRecords == null) {
			if (other.transactionStatusRecords != null)
				return false;
		} else if (!transactionStatusRecords.equals(other.transactionStatusRecords))
			return false;
		return true;
	}

	@Override
	public String toString() {
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd H:mm:ss");
		String createTimeStr=sdf.format(createTime);
		return "[id]:"+id+",[customer id]:"+customer.getId()+",[total]:"+total+",[create time]:"+createTimeStr;
	}

	
	
	
	
	
}
